﻿using System;
using System.Data;
using System.Windows.Forms;
using Trimmer.Utility;
using System.IO;

namespace Trimmer
{
    public partial class Suz : Form
    {

        string lstF, lstR;
        public Suz(string lstF, string lstR, string Kategori)
        {
            InitializeComponent();
            this.lstF = lstF;
            this.lstR = lstR;
            this.Kategori = Kategori;
        }

        private void Suz_Load(object sender, EventArgs e)
        {
            DataTable dt = AppSession.DataManager.ExecuteDataTable("GetAksCrop", lstF, lstR, string.Empty);
            dataGridView1.DataSource = dt;
            dataGridView1.AutoResizeColumns();
            dataGridView1.ReadOnly = true;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.CellDoubleClick += dataGridView1_CellDoubleClick;
            dataGridView1.AllowUserToAddRows = false;

            dataGridView1.ClearSelection();
            foreach (DataGridViewRow r in dataGridView1.Rows)
                if (r.Cells["Kategori"].Value.ToString() == Kategori)
                    r.Selected = true;

            /*
            dataGridView1.ClearSelection();
            int rowHandle = dataGridView1.LocateByValue("Kategori", Kategori);
            if (rowHandle != GridControl.InvalidRowHandle)
                dataGridView1.SelectRow(rowHandle);
            */
        }

        public DataTable dtSel;
        public string Kategori;
        void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                Kategori = (string)dataGridView1["Kategori", e.RowIndex].Value;
                dtSel = AppSession.DataManager.ExecuteDataTable("GetAksCrop", lstF, lstR, Kategori);
                this.DialogResult = DialogResult.OK;
            }
        }

    }
}
